import * as types from '../action-types'
import { getToken } from '@/utils/auth'

/**
 * 用户信息
 */
const initUserInfo = {
  name: '',
  role: '',
  avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  token: getToken() || ''
}
export default function user(state = initUserInfo, action) {
  switch (action.type) {
    case types.USER_SET_USER_TOKEN:
      return {
        ...state,
        token: action.token
      }
    case types.USER_SET_USER_INFO:
      // console.log(action, state)
      return {
        ...state,
        name: action.name,
        role: action.roles,
        avatar: action.avatar
      }
    case types.USER_RESET_USER:
      return {}
    default:
      return state
  }
}
